

const items={
	login:"/pages/mylogin/index",
	home:"/pages/home/index",
	person:"/pages/src/person/person",
	school:"/pages/src/schoolinfo/schoolinfo",
	newsmsg:"/pages/src/newsmsg/newsmsg",
	classes:"/pages/src/classes/classes",
	play:"/pages/src/classes/play",
	foodslist:"/pages/src/foodslist/foodslist",
	children:"/pages/src/children/children",
	news_detail:"/pages/src/newsmsg/news_detail/index",
	person_detail:"/pages/src/person/person_detail/index",
	foodslist_detail:"/pages/src/foodslist/foodslist_detail/index",
	videolist:"/pages/src/videolist/videolist",
	imgwall:"/pages/src/imgwall/imgwall",
	fundetail:"/pages/src/fundetail/fundetail",
	messagedetail:"/pages/src/messagedetail/messagedetail"
}
const urlRequire = ['homepage','shoppingmall','wallet','transation','user','register','login','forget']
console.log(typeof uni.getStorageSync('$Route'));
const route = uni.getStorageSync('$Route')||{}
const methods = {
	push: "navigateTo",
	replace: "redirectTo",
	replaceAll: "reLaunch",
	pushTab: "switchTab",
	back: "navigateBack"
};
const pathOrNameToRoute=function(obj){
	if(items[obj.name]){
		return items[obj.name]
	}else{
		console.log('不存在路径：'+items[obj.name])
		return
	}
}
const checkPathargs=function(obj){
	if(!obj){
		console.log('缺少跳转参数obj:{name:"xxx"}')
		return false
	}
	if(!obj['name']){
		console.log('参数错误obj:{name:"xxx"}')
		return false
	}
	
	let path=pathOrNameToRoute(obj)
	route.query  = obj['query']?obj['query']:{}
	route.params = obj['params']?obj['params']:{}
	route.name=obj.name
	route.path=path
	//console.log(route);
	uni.setStorageSync('$Route',route)
	return true;
}
const push=function(obj){
	checkPathargs(obj)?next('navigateTo'):''
}
const pushTab=function(obj){
	checkPathargs(obj)?next('switchTab'):''
}
const replace=function(obj){
	checkPathargs(obj)?next('redirectTo'):''
}
const replaceAll=function(obj){
	checkPathargs(obj)?next('reLaunch'):''
}
const back=function(num){
	next('navigateBack',num)
}
const go=function(num){
	next('navigateBack',num)
}
const next=function(type,num){
	console.log(route)
	if(num){
		uni[type]({
			delta:Math.abs(Number(num)),
			animationType:'pop-out'
		})
	}else{
		uni[type]({
			url:route.path,
			success:(res)=>{
				// console.log(res);
			},
			fail:(err)=>{
				console.log(err);
			}
		})
	}
}
export default{push,pushTab,replace,replaceAll,back,go,route}